home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / OutOfPhase1.01Source / OutOfPhase Folder / Level 0 Macintosh 07Aug94 / Debug.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-01  |  5.9 KB  |  195 lines  |  [TEXT/KAHL]

  1. /* Debug.c */
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*    System Dependency Library for Building Portable Software               */
  5. /*    Macintosh Version                                                      */
  6. /*    Written by Thomas R. Lawrence, 1993 - 1994.                            */
  7. /*                                                                           */
  8. /*    This file is Public Domain; it may be used for any purpose whatsoever  */
  9. /*    without restriction.                                                   */
  10. /*                                                                           */
  11. /*    This package is distributed in the hope that it will be useful,        */
  12. /*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  13. /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                   */
  14. /*                                                                           */
  15. /*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
  16. /*                                                                           */
  17. /*****************************************************************************/
  18.  
  19. #include "MiscInfo.h"
  20. #include "Definitions.h"
  21. #include "Debug.h"
  22. #include "Audit.h"
  23.  
  24. #pragma options(pack_enums)
  25. #include <Quickdraw.h>
  26. #include <Windows.h>
  27. #include <Memory.h>
  28. #include <Controls.h>
  29. #include <OSEvents.h>
  30. #include <SegLoad.h>
  31. #include <TextEdit.h>
  32. #pragma options(!pack_enums)
  33.  
  34.  
  35. /* debugging function, use it to present message */
  36. #define MAINWINDOWCOORDS  70,40,512-70,342-120
  37. #define TEXTBOXCOORDS  8,24,512-70-70-8,342-120-40-8
  38. #define RESUMEBUTTONCOORDS  8,342-120-40-8-20,96+8,342-120-40-8
  39. #define QUITBUTTONCOORDS  120,342-120-40-8-20,96+128,342-120-40-8
  40.  
  41. /* if AbortFlag == True, then it is impossible to recover from error and */
  42. /* the application must be forced to quit */
  43. /* 'Message' is a C-String [null terminated] */
  44. #define EmergencyCacheSize (8192)
  45.  
  46.  
  47. EXECUTE(static MyBoolean    Inited = False;)
  48.  
  49. static Handle                            Emergency = NIL;
  50.  
  51.  
  52. /* turn off any weird options */
  53. #pragma options(!profile)
  54. #pragma options(!mc68020)
  55.  
  56.  
  57. void                            PRERR(int AbortFlag, char* Message)
  58.     {
  59.         WindowRecord        ErrorWindow;
  60.         Rect                        Bounds;
  61.         Rect                        TextRect;
  62.         EventRecord            MyEvent;
  63.         WindowPtr                WhichWindow;
  64.         ControlHandle        ResumeButton;
  65.         ControlHandle        QuitButton;
  66.         ControlHandle        WhichOne;
  67.         long                        NumChars;
  68.         short                        CommandKeyDown;
  69.  
  70.         if (Emergency != NIL)
  71.             {
  72.                 DisposHandle(Emergency);
  73.                 Emergency = NIL;
  74.             }
  75.         APRINT(("+PRERR: '%t'",Message));
  76.         #if ALWAYSRESUME
  77.             AbortFlag = AllowResume; /* while we're debugging, we can resume */
  78.         #endif
  79.         SetRect(&Bounds,MAINWINDOWCOORDS);
  80.         NewWindow(&ErrorWindow,&Bounds,"\p",True,1,(GrafPort*)-1,False,0);
  81.         SelectWindow((WindowPtr)&ErrorWindow);  /* force it to be on top */
  82.         SetRect(&Bounds,RESUMEBUTTONCOORDS);
  83.         ResumeButton = NewControl((WindowPtr)&ErrorWindow,&Bounds,
  84.             "\pResume",True,0,0,0,pushButProc,0);
  85.         SetRect(&Bounds,QUITBUTTONCOORDS);
  86.         QuitButton = NewControl((WindowPtr)&ErrorWindow,&Bounds,
  87.             "\pQuit",True,0,0,0,pushButProc,0);
  88.         if (AbortFlag == ForceAbort)
  89.             {
  90.                 HiliteControl(ResumeButton,255);  /* make it inactive */
  91.             }
  92.         FlushEvents(everyEvent,0);
  93.         while (True)
  94.             {
  95.                 GetNextEvent(everyEvent,&MyEvent);
  96.                 CommandKeyDown = ((MyEvent.modifiers & cmdKey) != 0);
  97.                 switch (MyEvent.what)
  98.                     {
  99.                         case mouseDown:
  100.                             GlobalToLocal(&MyEvent.where);
  101.                             if (FindControl(MyEvent.where,(WindowPtr)&ErrorWindow,&WhichOne) != 0)
  102.                                 {
  103.                                     if (WhichOne != NIL)
  104.                                         {
  105.                                             if (WhichOne == QuitButton)
  106.                                                 {
  107.                                                     if (TrackControl(QuitButton,MyEvent.where,NIL) != 0)
  108.                                                         {
  109.                                                             APRINT(("-PRERR: abort"));
  110.                                                             ENDAUDIT();
  111.                                                             if (CommandKeyDown)
  112.                                                                 {
  113.                                                                     goto SkipBrk1Point;
  114.                                                                 }
  115.                                                             #if DEBUGGER_PRESENT
  116.                                                                 #if DEBUG
  117.                                                                     Debugger(); /* break point */
  118.                                                                 #endif
  119.                                                             #endif
  120.                                                          SkipBrk1Point:
  121.                                                             ExitToShell(); /* exit from the program */
  122.                                                         }
  123.                                                 }
  124.                                             if (WhichOne == ResumeButton)
  125.                                                 {
  126.                                                     if (TrackControl(ResumeButton,MyEvent.where,NIL) != 0)
  127.                                                         {
  128.                                                             goto ExitPoint;
  129.                                                         }
  130.                                                 }
  131.                                         }
  132.                                 }
  133.                             break;
  134.                         case updateEvt:
  135.                             BeginUpdate((WindowPtr)&ErrorWindow);
  136.                             SetPort(&ErrorWindow.port);
  137.                             TextFont(0);  /* system font */
  138.                             TextFace(0);  /* normal */
  139.                             TextMode(srcOr);
  140.                             TextSize(12);  /* 12 point */
  141.                             SpaceExtra(0);  /* no extra space */
  142.                             MoveTo(8,16);
  143.                             DrawString("\pAn Internal Program Error Occurred:");
  144.                             SetRect(&TextRect,TEXTBOXCOORDS);
  145.                             /* finding length of message string */
  146.                             NumChars = 0;
  147.                             while ( ((char*)Message)[NumChars] != 0)
  148.                                 {
  149.                                     NumChars += 1;
  150.                                 }
  151.                             TextBox(Message,NumChars,&TextRect,teJustLeft);
  152.                             DrawControls((WindowPtr)&ErrorWindow);
  153.                             EndUpdate((WindowPtr)&ErrorWindow);
  154.                             break;
  155.                         default:
  156.                             break;
  157.                     }
  158.             }
  159.      ExitPoint:
  160.         CloseWindow((WindowPtr)&ErrorWindow);
  161.         APRINT(("-PRERR"));
  162.         GetNextEvent(activMask,&MyEvent); /* clear activate event for underlying window */
  163.         if (CommandKeyDown)
  164.             {
  165.                 goto SkipBrk2Point;
  166.             }
  167.         Emergency = NewHandle(EmergencyCacheSize);
  168.         #if DEBUGGER_PRESENT
  169.             #if DEBUG
  170.                 Debugger(); /* break point */
  171.             #endif
  172.         #endif
  173.      SkipBrk2Point:
  174.         return;
  175.     }
  176.  
  177.  
  178. void                            Eep_InitPRERR(void)
  179.     {
  180.         ERROR(Inited,PRERR(ForceAbort,"InitPRERR called more than once."));
  181.         Emergency = NewHandle(EmergencyCacheSize);
  182.         EXECUTE(Inited = True;)
  183.     }
  184.  
  185.  
  186. void                            Eep_ShutdownPRERR(void)
  187.     {
  188.         ERROR(!Inited,PRERR(ForceAbort,"ShutdownPRERR:  not initialized"));
  189.         if (Emergency != NIL)
  190.             {
  191.                 DisposHandle(Emergency);
  192.                 Emergency = NIL;
  193.             }
  194.     }
  195.